﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StoryTeller.Domain;
using StoryTeller.Repository;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace StoryTeller.UnitTest.Repository
{
    [TestClass]
    public class GroupRepositoryUnitTest
    {
        public GroupRepository repository { get { return new GroupRepository(); } }

        public Group group
        {
            get
            {
                return new Group()
                {
                    IsPublic = true,
                    Title = "Group test001...",
                    Owner = new UserRepository().Select().First(),
                    //Contributors = new UserRepository().Select().Take(2).ToList()
                };
            }
        }

        [TestMethod]
        public void Insert()
        {
            repository.Insert(group);
        }

        [TestMethod]
        public void Update()
        {
            Group g = repository.Select().Last();
            g.Title += " = updated" + DateTime.Now.ToShortDateString();

            repository.Update(g);
        }

        [TestMethod]
        public void Delete()
        {
            Group g = repository.Select().Last();

            repository.Delete(g.Id);
        }

        [TestMethod]
        public void Select()
        {
            ICollection<Group> coll = repository.Select();

            Assert.IsNotNull(coll);
        }

        [TestMethod]
        public void SelectById()
        {
            Group g = repository.Select().Last();

            repository.Delete(g.Id);

            Assert.IsNotNull(g);
        }
    }
}
